'use strict';

const dayjs = require("dayjs");
module.exports = app => {
  const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;

  const School = app.model.define('school', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    lang: STRING,
    code: {
      type: STRING(30),
      allowNull: false,
      comment: '编号',
    },
    name: {
      type: STRING(30),
      allowNull: false,
      comment: '学校名称',
    },
    post_url: {
      type: STRING(255),
      allowNull: false,
      comment: '封面',
    },
    images: {
      type: TEXT,
      allowNull: false,
      comment: '学校简介',
    },
    desc: {
      type: STRING,
      comment: '学校简介',
    },
    sort: {
      type: INTEGER,
      allowNull: false,
      comment: '排序',
    },
    status: {
      type: INTEGER,
      allowNull: false,
      comment: '状态',
    },
    create_time: {
      type: DATE,
      get() {
        return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    updated_time: {
      type: DATE,
      get() {
        return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
      }
    }
  }, {
    tableName: 'school',
    comment: '学校表',
    timestamps: true, // 启用时间戳(createdAt, updatedAt)
    createdAt: 'create_time',
    updatedAt: 'updated_time'
  });

  return School;
};
// 根据以上字段生成mysql建表语句
// CREATE TABLE `school` (
//   `id` int(11) NOT NULL AUTO_INCREMENT,
//   `name` varchar(255) DEFAULT NULL,
//   `create_time` datetime DEFAULT NULL,
//   `updated_time` datetime DEFAULT NULL,
//   PRIMARY KEY (`id`)
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
